package com.strong.task1.mr;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class WordSortReducer extends Reducer<LongWritable, NullWritable, Text, NullWritable> {
    private static int lineNum = 1;

    @Override
    protected void reduce(LongWritable key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        Text k = new Text();
        for (NullWritable value : values) {
            //可能出现文件中的数字会有重复，所以即使key一样，也要都打印出来
            k.set(lineNum++ + "\t" +key.toString());
            context.write(k, value);
        }
    }
}
